package com.example.activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import androidx.appcompat.app.AppCompatActivity;

public class MainActivity4 extends AppCompatActivity implements View.OnClickListener {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main4);
        findViewById(R.id.bt4_back).setOnClickListener(this);
        findViewById(R.id.bt4_dial).setOnClickListener(this);
        findViewById(R.id.bt4_send).setOnClickListener(this);
        findViewById(R.id.bt4_go).setOnClickListener(this);
        findViewById(R.id.bt4_hello).setOnClickListener(this);
        findViewById(R.id.bt4_data).setOnClickListener(this);
        findViewById(R.id.bt4_meta).setOnClickListener(this);

    }

    @Override
    public void onClick(View v) {
        int id = v.getId();
        if (id == R.id.bt4_back) {
            finish();
        } else if (id == R.id.bt4_dial) {
            // set方法设置意图
            Intent intent = new Intent();
            intent.setAction(Intent.ACTION_DIAL);
            Uri uri = Uri.parse("tel:123456");
            intent.setData(uri);
            startActivity(intent);
        } else if (id == R.id.bt4_send) {
            // 构造方法设置意图
            Uri uri = Uri.parse("smsto:123456");
            Intent intent = new Intent(Intent.ACTION_SENDTO, uri);
            startActivity(intent);
        } else if (id == R.id.bt4_go) {
            Intent intent = new Intent("android.intent.action.ACTIONTEST");
            // 可省略，会自动添加
            intent.addCategory(Intent.CATEGORY_DEFAULT);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else if (id == R.id.bt4_hello) {
            // 跳转到helloworld程序上
            Intent intent = new Intent("android.intent.action.STARTHELLO");
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else if (id == R.id.bt4_data) {
            Intent intent = new Intent(this, SendDataActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        } else if (id == R.id.bt4_meta) {
            Intent intent = new Intent(this, MetaDataActivity.class);
            intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(intent);
        }
    }
}
